package com.woniuxy.banka.service.impl;

import com.woniuxy.banka.mapper.BankAMapper;
import com.woniuxy.banka.service.BankAService;
import com.woniuxy.commons.entity.Bank;
import com.woniuxy.commons.service.BankBService;
import com.woniuxy.commons.util.ResponseResult;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
class BankAServiceImpl implements BankAService {
    @Resource
    private BankAMapper bankAMapper;

    @Resource
    private BankBService bankBService;

    @GlobalTransactional
    @Override
    public int update() {
        //1.让bankB先执行加钱操作，然后根据结果执行其它逻辑
        //Bank dest = new Bank(2001,100,"lisi");  //dest  需要加钱的账号
        //加钱
        ResponseResult responseResult = bankBService.update(2001,100);

        //2.判断结果
        if (responseResult.getMessage().equals("success")){
            Bank src = new Bank(1001,100,"zhangsan"); //转出的人
            //减钱
            bankAMapper.update(src);
        }

        return 1;
    }
}
